<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box1 {
      display: flex;
      width: 500px;
      height: 50px;
      border: 1px solid #333;
    }
    .box1 span {
      /* flex: 4; */
      flex: 1;
      height: 50px;
      background-color: #ccc;
      text-align: center;
      line-height: 50px;
      font-size: 18px;
    }
    .box1 span:hover {
      background-color: rgb(236, 188, 100);
    }
    .box2 {
      display:flex; 
      width: 500px;
      height: 120px;
    }
    .box2 > div {
    visibility: hidden;
    
  }
    .box2 a {
      text-decoration: none;
      color: black;
      font-size: 15px;
    }
    .box2 .login span {
      text-align: center;
      line-height: 40px;
      display: block;
      height: 40px;
      width: 125px;
      background-color: rgb(197, 197, 236);
    }
    .box2 .weibo span {
      text-align: center;
      line-height: 40px;
      display: block;
      height: 40px;
      width: 125px;
      background-color: rgb(224, 236, 197);

    }
    .box2 .blog span {
      text-align: center;
      line-height: 40px;
      display: block;
      height: 40px;
      width: 125px;
      background-color: rgb(236, 197, 230);
    }
    .box2 .email span{
      text-align: center;
      line-height: 40px;
      display: block;
      height: 40px;
      width: 125px;
      background-color: rgb(231, 163, 111);
    }
  </style>
</head>
<body>
  <div class="box1">
    <span id="A"><label>登录</label></span>
    <span id="B"><label>微博</label></span>
    <span id="C"><label>博客</label></span>
    <span id="D"><label>邮箱</label></span>
  </div>
  <div class="box2">
    <!-- 登录板块 -->
    <div class="login">
      <span><a href="#">账号密码登录</a></span>
      <span><a href="#">QQ登录</a></span>
      <span><a href="#">微信登录</a></span>
    </div>
    <!-- 微博板块 -->
    <div class="weibo">
      <span><a href="#">私信</a></span>
      <span><a href="#">评论</a></span>
      <span><a href="#">@我</a></span>
    </div>
    <!-- 博客板块 -->
    <div class="blog">
      <span><a href="#">关注</a></span>
      <span><a href="#">通知</a></span>
      <span><a href="#">私信</a></span>
    </div>
    <!-- 邮箱板块 -->
    <div class="email">
      <span><a href="#">收件箱</a></span>
      <span><a href="#">发件箱</a></span>
      <span><a href="#">草稿箱</a></span>
    </div>
  </div>
  <script>
    var login1=document.getElementById('A');
    var weibo1=document.getElementById('B');
    var blog1=document.getElementById('C');
    var email1=document.getElementById('D');
    var login=document.getElementsByClassName('login')[0];
    var weibo=document.getElementsByClassName('weibo')[0];
    var blog=document.getElementsByClassName('blog')[0];
    var email=document.getElementsByClassName('email')[0];

    // 封装隐藏所有板块的函数（将display改为visibility）
  function hideAll() {
    login.style.visibility = 'hidden';
    weibo.style.visibility = 'hidden';
    blog.style.visibility = 'hidden';
    email.style.visibility = 'hidden';
  }

  // 鼠标悬停显示对应板块
  login1.onmouseover = function(){
    hideAll();
    login.style.visibility = 'visible';
  }
  weibo1.onmouseover = function(){
    hideAll();
    weibo.style.visibility = 'visible';
  }
  blog1.onmouseover = function(){
    hideAll();
    blog.style.visibility = 'visible';
  }
  email1.onmouseover = function(){
    hideAll();
    email.style.visibility = 'visible';
  }

  // 鼠标离开时仅隐藏当前对应板块
login1.onmouseout = function() {
  if (login.style.visibility === 'visible') {
    login.style.visibility = 'hidden';
  }
}
weibo1.onmouseout = function() {
  if (weibo.style.visibility === 'visible') {
    weibo.style.visibility = 'hidden';
  }
}
blog1.onmouseout = function() {
  if (blog.style.visibility === 'visible') {
    blog.style.visibility = 'hidden';
  }
}
email1.onmouseout = function() {
  if (email.style.visibility === 'visible') {
    email.style.visibility = 'hidden';
  }
}


  // 初始化隐藏所有板块（页面加载时执行）
  hideAll();
  </script>
</body>
</html>